﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'usp_UPDMS_COM_PGM_GRID_Update')
	BEGIN
		DROP Procedure usp_UPDMS_COM_PGM_GRID_Update
	END
GO

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
/******************************************************************************
**	Name : usp_UPDMS_COM_PGM_GRID_Update
**	Desc : 프로그램별 그리드관리을 수정한다.
**	Test Exec Query : Exec usp_UPDMS_COM_PGM_GRID_Update
**	Called by : Com_Dac_UPDMS_COM_PGM_GRID.cs
**	Program ID : Com1019m
**	Auth : 송시명
**	Date : 2011-02-11
*******************************************************************************
**	Change History
*******************************************************************************
**	Date:		Author:		Description:
**	--------	--------	---------------------------------------
**	
*******************************************************************************/
CREATE PROC [dbo].[usp_UPDMS_COM_PGM_GRID_Update]
@Seq int,
@Pgm_Id nvarchar(20),
@Grid_Id nvarchar(50),
@Create_User nvarchar(20),
@Create_Dt datetime,
@Update_User nvarchar(20),
@Update_Dt datetime
AS
SET NOCOUNT OFF

DECLARE @preGridId nvarchar(50)

--업데이트 하기전 Grid_Id조회
SET @preGridId = (SELECT Grid_Id FROM UPDMS_COM_PGM_GRID WITH(NOLOCK) WHERE Seq = @Seq)

--Grid_Id가 변경되었다면 UPDMS_COM_PGM_GRID_COLUMN도 변경
IF (@preGridId <> @Grid_Id)
BEGIN
  UPDATE UPDMS_COM_PGM_GRID_COLUMN
     SET Grid_Id = @Grid_Id,
         Update_User = @Update_User,
         Update_Dt = GETDATE()
   WHERE Pgm_Id =  @Pgm_Id
     AND Grid_Id = @preGridId
END


UPDATE UPDMS_COM_PGM_GRID
   SET Grid_Id = @Grid_Id,
       Update_User = @Update_User,
       Update_Dt = GETDATE()
 WHERE Seq = @Seq

GO